package org.ekstrabilet.ticket.logic;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import org.ekstrabilet.database.connection.ConnectionManager;
import org.ekstrabilet.database.statements.Statements;
import org.ekstrabilet.stadium.logic.StadiumLogic;
import org.ekstrabilet.ticket.beans.Ticket;
import org.ekstrabilet.user.beans.User;
import org.ekstrabilet.user.logic.UserLogic;

public class TicketLogic {
	

	private static TicketLogic ticketLogic= null;
	
	private TicketLogic(){
		
	}
	
	
	public void addTicket(Ticket ticket){
		User user= UserLogic.getInstance().getUsers().get(0);
		Connection conn= ConnectionManager.getManager().getConnection();
		try {
			PreparedStatement stm= conn.prepareStatement(Statements.INSERT_TICKET);
			stm.setInt(1, ticket.getGameId());
			stm.setInt(2, ticket.getSectorId());
			stm.setInt(3, ticket.getRow());
			stm.setInt(4, ticket.getSeat());
			stm.setInt(5, user.getUserID());
			stm.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally{
			try {
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
	}
	
	public static TicketLogic getInstance(){
		if(ticketLogic == null)
			ticketLogic= new TicketLogic();
		return ticketLogic;
	}
}
